package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserPersonDetailBean;
import com.koron.css2.clientCenter.mapper.UserPersonDetailMapper;
import com.koron.css2.clientCenter.queryBean.UserPersonDetailQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class UserPersonLadderNum implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		try {
			UserPersonDetailQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserPersonDetailQueryBean.class);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			UserPersonDetailMapper mapper = factory.getMapper(UserPersonDetailMapper.class);
			List<UserPersonDetailBean> list = mapper.getPersonDetailByUserNo(bean.getUserNo());
			for (UserPersonDetailBean userPersonDetailBean : list) {
				if (StringUtils.isNotBlank(userPersonDetailBean.getCertType())) {
					userPersonDetailBean.setCertType(Tools.getDicNameByCodeAndValue(factory, "IDT", userPersonDetailBean.getCertType()));
				}
			}
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			info.setData(new PageInfo<>(list));
			return info;
		} catch (Exception e) {
			logger.error("用水人口详情查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "用水人口详情查询失败", null);
		}
	}
}
